package org.wishwork.api.express.register;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.wishwork.api.Api;
import org.wishwork.context.Context;
import org.wishwork.helper.HttpHelper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @description: 批量快递登记
 * @author: WangYX
 * @create: 2022-04-13 09:55
 * @Version: 1.0.0
 **/

public class ExpressRegisterApi extends Api<ExpressRegisterResponse, List<ExpressRegisterRequest>> {

    private static final Logger log = LoggerFactory.getLogger(ExpressRegisterApi.class);

    private Context context;

    public ExpressRegisterApi(Context context) {
        this.context = context;
    }

    @Override
    protected String query(List<ExpressRegisterRequest> expressRegisterRequests) throws Exception {
        String url = "/open/express/register/upload";
        List<Map<String, Object>> params = new ArrayList<>();
        for (ExpressRegisterRequest expressRegisterRequest : expressRegisterRequests) {
            Map<String, Object> map = new HashMap<>();
            map.put("l_id", expressRegisterRequest.getLId());
            if (StrUtil.isNotEmpty(expressRegisterRequest.getLName())) {
                map.put("l_name", expressRegisterRequest.getLName());
            }
            if (StrUtil.isNotEmpty(expressRegisterRequest.getWarehouseRemark())) {
                map.put("warehouseRemark", expressRegisterRequest.getWarehouseRemark());
            }
        }
        String biz = JSON.toJSONString(params);
        return HttpHelper.sendRequest(biz, url);
    }

    @Override
    protected ExpressRegisterResponse process(JSONObject data, List<ExpressRegisterRequest> expressRegisterRequests) throws Exception {
        return null;
    }
}
